$(function() {
	modal.prepare();
	examing.initial();

});

var examing = {
	initial : function initial() {
		$(window).scroll(examing.fixSideBar);
		// this.methedRunTimes(this.initialModel);
		// this.methedRunTimes(this.bindNaviBehavior);
		this.cachedJQueryDom;
		this.methedRunTimes(this.refreshNavi);
		// this.methedRunTimes(this.addNumber);
		this.cachedJQueryDom.QItems = $("#question-navi-content").children();
		// this.methedRunTimes(this.bindOptClick);
		// this.methedRunTimes(this.securityHandler);
		// this.methedRunTimes(this.updateSummery);
		this.methedRunTimes(this.bindfocus);
		// this.methedRunTimes(this.bindFinishOne);
		// this.methedRunTimes(this.startTimer);
		// this.methedRunTimes(this.bindSwitchQuestion);
		this.methedRunTimes(this.bindSubmitQuestion);
		// this.methedRunTimes(this.loadStatus);
		this.methedRunTimes(this.bindShouCangQuestion);
		this.methedRunTimes(this.conSubmitbind);
		/*
		 * this.initialModel(); this.bindNaviBehavior(); this.refreshNavi();
		 * this.addNumber(); this.bindOptClick(); // this.securityHandler(); //
		 * this.updateSummery(); this.bindfocus(); this.bindFinishOne(); //
		 * this.startTimer(); this.bindSwitchQuestion();
		 * this.bindSubmitQuestion(); this.loadStatus(); //收藏
		 * this.bindShouCangQuestion();
		 */
	},
	fixSideBar : function fixSideBar() {
		var nav = $("#question-navi");
		var title = $("#exampaper-title");
		var container = $("#exampaper-desc-container");
		var paper = $("#exampaper-body");
		if ($(this).scrollTop() > 147) {
			nav.addClass("fixed");
			title.addClass("exampaper-title-fixed");
			container.addClass("exampaper-desc-container-fixed");
			paper.addClass("exampaper-body-fixed");
		} else {
			nav.removeClass("fixed");
			title.removeClass("exampaper-title-fixed");
			container.removeClass("exampaper-desc-container-fixed");
			paper.removeClass("exampaper-body-fixed");
		}
	},
	examModel : examModel = true,
	bindShouCangQuestion : function bindShouCangQuestion(){
		examing.cachedJQueryDom.Questions.find('button').click(function(){
			var isshow = $(this).data('show');
			var thisquestion  = $(this).parent().parent();
			if(isshow == '1'){
				// 显示答案
				thisquestion.find(".answer-desc").show();
				thisquestion.find(".answer-desc-detail").hide();
				$(this).data('show', '0');
				$(this).text('隐藏答案');
			}else{
				thisquestion.find(".answer-desc").hide();
				$(this).data('show', '1');
				$(this).text('查看答案');
			}
		});
/*
 * $(".shoucang").click(function(){ var _this = $(this); var thisquestion =
 * $(this).parent().parent();//$(".question:visible"); var answer =
 * examing.getAnswerValue(thisquestion); var data = new Object(); data.myAnswer =
 * answer; data.questionId = thisquestion.find(".question-id").text();
 * data.questionTypeId = thisquestion.find(".question-type-id").text();
 * data.pointId = thisquestion.find(".knowledge-point-id").text(); data.answer =
 * thisquestion.find(".answer_value").text();
 * 
 * 
 * if(_this.data('flag') == 'true'){
 * 
 * //取消收藏
 * 
 * var requestSc = $.ajax({ headers : { 'Accept' : 'application/json',
 * 'Content-Type' : 'application/json' }, type : "POST", async:false, url :
 * "student/question-collect-un", data : JSON.stringify(data) });
 * 
 * requestSc.done(function(message, tst, jqXHR) { if
 * (!util.checkSessionOut(jqXHR)) return false; if (message.result == "success") {
 * _this.css('color', 'rgb(96, 106, 108)'); _this.data('flag', 'false'); } else {
 * util.error(message.result); } });
 * 
 * 
 * }else{
 * 
 * //发送收藏请求， 成功则标出来 var requestSc = $.ajax({ headers : { 'Accept' :
 * 'application/json', 'Content-Type' : 'application/json' }, type : "POST",
 * async:false, url : "student/question-collect", data : JSON.stringify(data)
 * });
 * 
 * requestSc.done(function(message, tst, jqXHR) { if
 * (!util.checkSessionOut(jqXHR)) return false; if (message.result == "success") {
 * _this.css('color', 'red'); _this.data('flag', 'true'); } else {
 * util.error(message.result); } }); } });
 */
	},
	
	initialModel : function initialModel(){
		$(".answer-desc").hide();
		$(".question-point-content").hide();
		
	/*	*//** * *//*
				 * $("#question-submit .btn").on("click",function(){ var _this =
				 * this; var qtype = parseInt($(_this).data("type")) - 1;
				 * examing.doQuestionFilt(examing.questiontypes[qtype].code);
				 * });
				 */
		// console.log(new Date());
	},
	

	bindNaviBehavior : function bindNaviBehavior() {

		var nav = $("#question-navi");
		var naviheight = $("#question-navi").height() - 33;
		var bottompx = "-" + naviheight + "px;";
		// alert(naviheight);

		var scrollBottomRated = $("footer").height() + 2 + 100 + naviheight;
		// alert($("footer").height() );
		// alert(scrollBottomRated);

		$("#exampaper-footer").height($("#question-navi").height());

		nav.css({
			width: '225px',
		});

		// nav.attr("style", "position : \"fixed\";bottom:-" + naviheight +
		// "px;");

		/*
		 * $(window).scroll(function() { var nav = $("#question-navi"); var
		 * scrollBottom = document.body.scrollHeight - $(this).scrollTop() -
		 * $(window).height(); if (scrollBottom > scrollBottomRated) { //
		 * nav.addClass("fixed-navi"); var naviheight =
		 * $("#question-navi").height() - 33; // nav.attr("style", "bottom:-" +
		 * naviheight + "px;"); if (nav.css("position") == "relative") {
		 * nav.css({ position : 'fixed', bottom : "-" + naviheight + "px" }); } //
		 * nav.css({ // // position : 'fixed', // bottom : "-" + naviheight +
		 * "px" // });
		 *  } else { // nav.removeClass("fixed-navi"); // nav.attr("style", "");
		 * nav.css({ position : 'relative', bottom : 0 }); }
		 * 
		 * });
		 */

		$("#question-navi-controller").click(function() {
			var scrollBottom = document.body.scrollHeight - $(window).scrollTop() - $(window).height();

			var nav = $("#question-navi");
			var attr = nav.attr("style");
		
	

			if (nav.css("position") == "fixed") {
				if (nav.css("bottom") == "0px") {
					nav.css({
						bottom : "-" + naviheight + "px"
					});
				} else {
					nav.css({
						bottom : 0
					});
				}

			}

		});
		// console.log("end:"+new Date());
	},

	securityHandler : function securityHandler() {
// 右键禁用
		
		if (document.addEventListener) {
			document.addEventListener("contextmenu", function(e) {
				 e.preventDefault();
			 }, false);
		} else {
			document.attachEvent("contextmenu", function(e) {
				 e.preventDefault();
			 });
		}
		
// document.addEventListener('contextmenu', function(e) {
// e.preventDefault();
// }, false);

		$(window).bind('beforeunload', function() {
			return "考试正在进行中...";
		});
	},

	/**
	 * 刷新试题导航
	 */
	refreshNavi : function refreshNavi() {
		$("#exam-control #question-navi #question-navi-content").empty();
		var questions = examing.cachedJQueryDom.Questions;// $("li.question");
		var questionhistorys = $("#question-history").val();
		questions.each(function(index, item) {
		    var isdo = "";
			$(questionhistorys.split(',')).each(function(j,jtem){
				if(item && jtem && $(item).find('.question-id').text() ===  jtem){
					isdo = "question-isdo";
				}
			});
			var btnhtml = "<a class=\"question-navi-item "+isdo+" \">" + (index + 1) + "</a>";
			$("#question-navi-content").append(btnhtml);
			// 添加题目编号
			$(this).find(".question-no").text(index + 1 + ".");
			// 添加查看答案按钮
			$(item).find('.question-title')
			.append('<button class="btn btn-success btn-sm xsda" style="float: right;" data-show="1">查看答案</button>');
		
		});
		// console.log("refreshNavi end:"+new Date());
	},

	/**
	 * 更新题目简介信息
	 */
	updateSummery : function updateSummery() {
		if ($(".question").length === 0) {
			return false;
		}
		var questiontypes = examing.questiontypes;
		var summery = "";
		for (var i = 0; i < questiontypes.length; i++) {
			var question_sum_q = $("." + questiontypes[i].code).length;
			if (question_sum_q == 0) {
				continue;
			} else {
				summery = summery + "<span class=\"exampaper-filter-item efi-" + questiontypes[i].code + "\">" 
				+ questiontypes[i].name + "[<span class=\"efi-fno\">0</span>/<span class=\"efi-tno\">" 
				+ $("." + questiontypes[i].code).length + "</span>]<span class=\"efi-qcode\" style=\"display:none;\">" 
				+ questiontypes[i].code + "</span></span>";
			}
		}
		// summery = summery.substring(0, summery.length - 2);
		$("#exampaper-desc").html(summery);
		// console.log("updateSummery end:"+new Date());
		
	},

	questiontypes : new Array({
		"type" : 1,
		"name" : "单选题",
		"code" : "qt-singlechoice"
	}, {
		"type" : 2,
		"name" : "多选题",
		"code" : "qt-multiplechoice"
	}, {
		"type" : 3,
		"name" : "判断题",
		"code" : "qt-trueorfalse"
	}, {
		"type" : 4,
		"name" : "填空题",
		"code" : "qt-fillblank"
	}, {
		"type" : 5,
		"name" : "简答题",
		"code" : "qt-shortanswer"
	}, {
		"type" : 6,
		"name" : "论述题",
		"code" : "qt-essay"
	}, {
		"type" : 7,
		"name" : "分析题",
		"code" : "qt-analytical"
	}, {
		"type" : 8,
		"name" : "识绘图",
		"code" : "qt-mark"
	}),
	/**
	 * 绑定考题focus事件(点击考题导航)
	 */
	bindfocus : function bindfocus() {
		$("#question-navi").delegate("a.question-navi-item ", "click", function() {
			var clickindex = this.text;
			var questions = examing.cachedJQueryDom.Questions;// $("#exampaper-body
																// li");
			// questions.hide();
			// $(questions[clickindex]).show();
			$(".qni-selected").removeClass("qni-selected");
			$(examing.cachedJQueryDom.QItems[clickindex-1]).addClass("qni-selected");
			var targetQuestion = questions[clickindex-1];
			// var targetQuestionType =
			// $(questions[clickindex]).find(".question-type").text();
			// examing.doQuestionFilt("qt-" + targetQuestionType);
			examing.scrollToElement($(targetQuestion),0,-100);
			
		});
		// console.log("updateSummery end:"+new Date());
	},	
	
	scrollToElement : function scrollToElement(selector, time, verticalOffset) {
		time = typeof (time) != 'undefined' ? time : 500;
		verticalOffset = typeof (verticalOffset) != 'undefined' ? verticalOffset : 0;
		element = $(selector);
		offset = element.offset();
		offsetTop = offset.top + verticalOffset;
		$('html, body').animate({
			scrollTop : offsetTop
		}, time);
	},



	/**
	 * 完成一道题触发的function
	 */
	bindFinishOne : function bindFinishOne() {
		$(".question input[type=radio]").change(function() {
			var current_index = $("li.question").index($(this).parent().parent());
			$($("a.question-navi-item")[current_index]).addClass("pressed");
			$(this).parent().parent().find(".question-list-item-selected").removeClass("question-list-item-selected");
			$(this).parent().addClass("question-list-item-selected");
		});

		$(".question input[type=checkbox]").change(function() {
			var current_question = $(this).parent().parent().parent().parent();
			var current_index = $("li.question").index(current_question);
			var checkedboxs = current_question.find("input[type=checkbox]:checked");
			if (checkedboxs.length > 0) {
				$($("a.question-navi-item")[current_index]).addClass("pressed");
			} else {
				$($("a.question-navi-item")[current_index]).removeClass("pressed");
			}
			
			if($(this).parent().hasClass("question-list-item-selected")){
				$(this).parent().removeClass("question-list-item-selected");
			}else{
				$(this).parent().addClass("question-list-item-selected");
			}
		});

		/*
		 * $(".question textarea").bind('input propertychange', function() {
		 * 
		 * var current_index =
		 * $("li.question").index($(this).parent().parent()); if ($(this).val() !=
		 * "") {
		 * $($("a.question-navi-item")[current_index]).addClass("pressed"); }
		 * else {
		 * $($("a.question-navi-item")[current_index]).removeClass("pressed"); }
		 * });
		 */
		// console.log("bindfinishone end:"+new Date());
	},
	
	bindSubmitQuestion : function bindSubmitQuestion(){
		examing.cachedJQueryDom.QInput.click(function(){
			$(this).find('input').prop('checked','checked');
			var thisquestion  = $(this).parent().parent().parent();// $(".question:visible");
			// 标记此题已做
			thisquestion.attr("data-isdo","true");
		/*
		 * if(thisquestion.hasClass("qt-finished")){ util.error("此题已经做完");
		 * return false; }
		 */ 
			
			// var = examing.getAnswerValue(thisquestion);
			
			// 答题卡selectd
			$("#question-navi-content .qni-selected").removeClass("qni-selected");
			var index = thisquestion.find('.question-no').text();
			index = parseInt(index.split('.')) - 1;
			var indexItem = examing.cachedJQueryDom.QItems[index];
			$(indexItem).addClass("qni-selected");
			/*
			 * each(function(i, item){ var index =
			 * thisquestion.find('.question-no').text(); index =
			 * index.split('.'); if($(item).text() == index[0]){
			 * $(item).addClass("qni-selected"); } });
			 */
			
		/*
		 * if(answer == "" || answer== null){ util.error("只有完成该题后才能提交答案！");
		 * return false; }else{
		 */
			/*
			 * if(answer == $(thisquestion).find(".answer_value").text()){
			 * $(thisquestion).find(".answer-desc-summary").addClass("answer-desc-success");
			 * $("#question-navi-content
			 * .qni-selected").addClass("qni-success").removeClass("qni-error");
			 * $("#question-navi-content .qni-selected").addClass("pressed");
			 * }else{
			 * $(thisquestion).find(".answer-desc-summary").addClass("answer-desc-error");
			 * $("#question-navi-content
			 * .qni-selected").addClass("qni-error").removeClass("qni-success");
			 * $("#question-navi-content .qni-selected").addClass("pressed"); }
			 */
			$("#question-navi-content .qni-selected").addClass("pressed")
			// examing.updateProgress();
			// }
			
			// thisquestion.addClass("qt-finished");
			// thisquestion.find(".question-body
			// input").attr("disabled","disabled");
			// thisquestion.find(".answer-desc").show();
			
			// TODO ajax request
			/*
			 * var data = new Object(); data.myAnswer = answer; data.questionId =
			 * thisquestion.find(".question-id").text(); data.questionTypeId =
			 * thisquestion.find(".question-type-id").text(); data.pointId =
			 * thisquestion.find(".knowledge-point-id").text(); data.answer =
			 * thisquestion.find(".answer_value").text();
			 */
			
// modal.showProgress();
			// $(this).attr("disabled","disabled");
			/*
			 * var request = $.ajax({ headers : { 'Accept' : 'application/json',
			 * 'Content-Type' : 'application/json' }, async:false, type :
			 * "POST", url : "student/practice-improve", data :
			 * JSON.stringify(data) });
			 */

			/*
			 * request.done(function(message, tst, jqXHR) { if
			 * (!util.checkSessionOut(jqXHR)) return false; if (message.result ==
			 * "success") { $(window).unbind('beforeunload'); //
			 * util.success("答案提交成功！"); var thisquestion =
			 * $(".question:visible");
			 * 
			 * if(thisquestion.find(".answer-desc-summary").hasClass("answer-desc-success")){ //
			 * $("#next-q-btn").click(); } } else { util.error(message.result); } //
			 * modal.hideProgress(); $("#submit-q-btn").removeAttr("disabled");
			 * }); request.fail(function(jqXHR, textStatus) {
			 * util.error("系统繁忙请稍后尝试"); // modal.hideProgress();
			 * $("#submit-q-btn").removeAttr("disabled"); });
			 */
			
		
// alert(answer);
			
		});
		
		// console.log("bindSubmitQuestion end:"+new Date());
	},
	getAnswerValue : function(obj){
		var thisquestion  = obj;// $(".question:visible");
		
		var answer;
		
		if(thisquestion.hasClass("qt-singlechoice")){
			var radio_checked = $(thisquestion).find("input[type=radio]:checked");
			var radio_all = $(thisquestion).find("input[type=radio]");
			if(radio_checked.length == 0){
				answer = "";
			}else{
				var current_index = $(radio_all).index(radio_checked);
				answer = String.fromCharCode(65 + current_index);
			}
			
		}else 	if( $(thisquestion).hasClass("qt-multiplechoice")){
			
			var checkbox_checked = $(thisquestion).find("input[type=checkbox]:checked");
			var checkbox_all = $(thisquestion).find("input[type=checkbox]");
			if(checkbox_checked.length == 0){
				answer = "";
			}else{
				var tm_answer = "";
				for(var l = 0 ; l < checkbox_checked.length; l++){
					var current_index = $(checkbox_all).index($(checkbox_checked[l]));
					tm_answer = tm_answer + String.fromCharCode(65 + current_index);
				}
				answer = tm_answer;
			}
		} else 	if( $(thisquestion).hasClass("qt-trueorfalse")){
			
			var radio_checked = $(thisquestion).find("input[type=radio]:checked");
			var radio_all = $(thisquestion).find("input[type=radio]");
			if(radio_checked.length == 0){
				answer = "";
			}else{
				var current_index = $(radio_all).index(radio_checked);
				answer = (current_index==0)?"对":"错";
			}
		}else{
			answer = $(thisquestion).find("textarea").val();
		}
		return answer;
	},
	
	disableInput : function disableInput(questionIndex){
		
	},

	/**
	 * 开始倒计时
	 */
	startTimer : function startTimer() {
		var timestamp = parseInt($("#exam-timestamp").text());
		var int = setInterval(function() {
			$("#exam-timestamp").text(timestamp);
			$("#exam-clock").text(examing.toHHMMSS(timestamp));

			timestamp++;
		}, 1000);
	},

	/**
	 * 时间formater
	 * 
	 * @param timestamp
	 * @returns {String}
	 */
	toHHMMSS : function toHHMMSS(timestamp) {
		var sec_num = parseInt(timestamp, 10);
		var hours = Math.floor(sec_num / 3600);
		var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
		var seconds = sec_num - (hours * 3600) - (minutes * 60);

		if (hours < 10) {
			hours = "0" + hours;
		}
		if (minutes < 10) {
			minutes = "0" + minutes;
		}
		if (seconds < 10) {
			seconds = "0" + seconds;
		}
		var time = hours + ':' + minutes + ':' + seconds;
		return time;
	},


	/**
	 * 对题目重新编号排序
	 */
	addNumber : function addNumber() {
		var questions = examing.cachedJQueryDom.Questions;// $("li.question");

		questions.each(function(index) {
			$(this).find(".question-no").text(index + 1 + ".");
		});
		// console.log("addNumber end:"+new Date());
	},


	
	
	bindSwitchQuestion : function bindSwitchQuestion(){
		// $(".question").hide();
		// $($(".question")[0]).show();
		
		$($("a.question-navi-item")[0]).addClass("qni-selected");
			
		$("#previous-q-btn").click(function(){
// examing.saveAnswerSheet();
			
			var allQuestion = $(".question");
			var thisquestion  = $(".question:visible");
			var thisindex = $(".question").index(thisquestion);
			if(thisindex == 0){
				return false;
			}else{
				// 很重要，切换题目时要清空评论
				$("#idx-hidden").val(1);
				$("#last-floor-hidden").val(0);
				$(".comment-list").html("");
				
				thisquestion.hide();
				$(allQuestion[thisindex - 1]).show();
				$(".qni-selected").removeClass("qni-selected");
				$($("a.question-navi-item")[thisindex - 1]).addClass("qni-selected");
				comment.queryComment();
			}
		});
		
		$("#next-q-btn").click(function(){
// examing.saveAnswerSheet();
			
			var allQuestion = $(".question");
			var thisquestion  = $(".question:visible");
			var thisindex = $(".question").index(thisquestion);
			var allQuestionLength = allQuestion.length;
			if(thisindex == allQuestionLength - 1){
				return false;
			}else{
				// 很重要，切换题目时要清空评论
				$("#idx-hidden").val(1);
				$("#last-floor-hidden").val(0);
				$(".comment-list").html("");
				
				thisquestion.hide();
				$(allQuestion[thisindex + 1]).show();
				$(".qni-selected").removeClass("qni-selected");
				$($("a.question-navi-item")[thisindex + 1]).addClass("qni-selected");
				comment.queryComment();
			}
		});
		// console.log("bindfinishone end:"+new Date());
	},
	
	loadStatus : function loadStatus(){
		modal.showProgress();
		
		var knowledgePointId = $("#knowledgePointId").text();
		var questionTypeId = $("#questionTypeId").text();
		var fieldId = $("#fieldId").text();
		
		var request = $.ajax({
			headers : {
				'Accept' : 'application/json',
				'Content-Type' : 'application/json'
			},
			type : "GET",
			async: false,
			cache: false,
			url : "student/practice-improve-his/" + fieldId + "/" + knowledgePointId + "/" + questionTypeId
		});
		
		request.done(function(data,tst,jqXHR) {
			if(!util.checkSessionOut(jqXHR))return false;
			
			if (data != null && data.length > 0 ) {
// alert(data);
				var questionList =  examing.cachedJQueryDom.Questions;// $("li.question");
				
				var lastestIndex = data[data.length - 1];
				
				if(data.length >= questionList.length){
					util.notify("您已经完成了该知识类型的所有题，不过您仍然可以继续练习这些题。");
					examing.cachedJQueryDom.QItems.addClass("pressed");
				}else{
					for(var i = 0; i <questionList.length; i++){
						var questionId = parseInt($(questionList[i]).find(".question-id").text());
						if($.inArray(questionId, data) != -1){
// alert($.inArray(questionId, data));
							$(examing.cachedJQueryDom.QItems[i]).addClass(
							"pressed");
						}
						
						if(lastestIndex == questionId ){
							var lastquestionIndex = i + 1;
							util.notify("您上次做到第 <strong>" + lastquestionIndex + "</strong> 题，现在您可以继续练习。");
							
// var clickindex = $("a.question-navi-item").index(this);
							var questions = examing.cachedJQueryDom.Questions;// $("li.question");
							// questions.hide();
							// $(questions[i]).show();
								
							// $(".qni-selected").removeClass("qni-selected");
							// $($("a.question-navi-item")[i]).addClass("qni-selected");
								
						}
					}
				}
				
				
				
			}
			// examing.updateProgress();
			modal.hideProgress();
		});
		
		request.fail(function(jqXHR, textStatus) {
			util.error("读取数据失败！");
// $("#answer-save-info").addClass("answer-save-info-error");
			modal.hideProgress();
			return false;
		});
		
		// console.log("loadStatus end:"+new Date());
	},
	
	updateProgress : function updateProgress(){
		var total = $("li.question").length;
		var finished = 100 * $("#question-navi-content .pressed").length;
		
		$(".h-progress span").attr("style","width:" + finished/total + "%;");
		
	},
	
	bindOptClick : function bindOptClick(){
		$("input[type=radio]").click(function(event){
			
			event.stopPropagation();
		});
		$("input[type=checkbox]").click(function(event){
			
			event.stopPropagation();
		});
		$(".question-list-item").click(function(){
			if($(this).find("input[type=radio]").length>0){
				$(this).find("input").click();
			}else if($(this).find("input[type=checkbox]").length>0){
				$(this).find("input").click();
			}
			
		/*
		 * if($(this).find("input").prop("checked")){
		 * $(this).find("input").prop("checked", false); }else{
		 * $(this).find("input").prop("checked", true); }
		 */
			
		});
		// console.log("bindOptClick end:"+new Date());
	},
	/**
	 * 切换到指定的题型
	 */
	doQuestionFilt : function doQuestionFilt(questiontype) {
		var questions = $("li.question");
		questions.hide();
		$("#exampaper-body ." + questiontype).show();
	},
	methedRunTimes: function methedRunTimes(func){
		 
		 var start = new Date().getTime();// 起始时间
		 
		 func();// 执行待测函数
		 
		 var end = new Date().getTime();// 结束时间
		 
		 console.log(func.name+"的执行时间:"+ (end - start)+"ms");
		 
		 return (end - start)+"ms";// 返回函数执行需要时间
		 
	},
	// dom元素缓存
	cachedJQueryDom : {
		"Questions" : $("#exampaper-body").children(),
		"QItems" : $("#question-navi-content").children(),
		"QInput" : $("#exampaper-body").children().find("li")
	},
	// 提交按钮绑定事件
	conSubmitbind : function conSubmitbind (){
		/** 练习结果统一提交* */
		$("#submit-con").on('click', function(){
			$("#submit-con").attr("disabled",'disabled');
			modal.showProgress();
			/** 获得已做的选项* */
			var form =  [];
			var isDoQuestions = [];
			var questionCount = 0;
			var questionFail = 0;
			examing.cachedJQueryDom.Questions.each(function(i, item){
				var data = new Object();
				var _item = $(item);
				if(_item.data("isdo")) {
					var answer = examing.getAnswerValue(_item);
					data.myAnswer = answer;
					data.questionId = _item.find(".question-id").text();
					data.questionTypeId = _item.find(".question-type-id").text();
					data.pointId = _item.find(".knowledge-point-id").text();
					data.answer = _item.find(".answer_value").text();
					form.push(data);
					var index = _item.find('.question-no').text();
					index = parseInt(index.split('.')) - 1;
					isDoQuestions.push(index);
					
					questionCount++;
					if(data.myAnswer !== data.answer){questionFail++;}
				}
				
			});
			
			if(questionCount == 0){
				modal.hideProgress();
				$("#submit-con").removeAttr("disabled");
				util.error("请至少完成一道题！");
				return;
			}
			
			/** *提交请求* */
			var request = $.ajax({
				headers : {
					'Accept' : 'application/json',
					'Content-Type' : 'application/json'
				},
				async:false,
				type : "POST",
				url : "student/practice-improves",
				data : JSON.stringify(form)
			});

		    request.done(function(message, tst, jqXHR) {
				if (!util.checkSessionOut(jqXHR))
					return false;
				if (message.result == "success") {
					
					/**更新试题导航标记为已做过**/
					$(isDoQuestions).each(function(i,item){
						var indexItem = examing.cachedJQueryDom.QItems[item];
						$(indexItem).addClass("question-isdo");	
					});
					
					
					$(window).unbind('beforeunload');
					var fieldid= $('#fieldId').text();
					var html = '<p>答案提交成功！答题：'+questionCount+'道 。错误：'+questionFail+'道</p>';
					if(questionFail > 0){
						html += '<p>错误的题目已收录在<a style="color:#33CCFF !important;" href="student/practice-incorrect/'+fieldid+'/1/0">错题集中营</a><p>';
					}
					util.success(html);
				} else {
					util.error(message.result);
				}
				modal.hideProgress();
				$("#submit-con").removeAttr("disabled");
		    });
		    
		    request.fail(function(jqXHR, textStatus) {
				util.error("系统繁忙请稍后尝试");
				modal.hideProgress();
				$("#submit-con").removeAttr("disabled");
		    });
		    
		});
		
	} 
};

var modal = {
	prepare : function prepare() {
		$("#all-con")
		.append("<div id=\"loading-progress\" style=\"display:none;\"><div id=\"loading-content\"> <h2>正在处理数据</h2><img class=\"loading-gif\" src=\"resources/images/loading.gif\"/><div> </div>");
		
	},
	showProgress : function showProgress() {
		$("#loading-progress").show();
	},

	hideProgress : function hideProgress() {
		$("#loading-progress").hide();
	}
};
